package com.xfp.mapper;

import com.github.pagehelper.Page;
import com.xfp.anntation.AutoFill;
import com.xfp.enumclass.OperationClass;
import com.xfp.pojo.dto.GoodsDto;
import com.xfp.pojo.dto.GoodsQueryDto;
import com.xfp.pojo.entity.Goods;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GoodsMapper {
    /**
     * 新增商品
     * @param goods
     * @return
     */
    @AutoFill(OperationClass.INSERT)
    @Insert("insert into tb_sku (sku_id,sku_name,sku_image,price,class_id,unit,brand_name,create_time,update_time,create_user,update_user)" +
            "values(#{skuId},#{skuName},#{skuImage},#{price},#{classId},#{unit},#{brandName},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    int insert(Goods goods);

    /**
     * 查询序列号是否重复
     */
    @Select("select * from tb_sku where sku_id =#{skuId}")
    Goods findById(String skuId);

    /**
     * 查询商品名称是否重复
     */
    @Select("select * from tb_sku where sku_name =#{skuName}")
    Goods findByName(String skuName);

    /**
     * 分页查询基础商品信息
     * @param goodsQueryDto
     */
    List<Goods> page(GoodsQueryDto goodsQueryDto);

    /**
     * 修改商品信息
     * @param dto
     * @return
     */
    @AutoFill(OperationClass.UPDATE)
    int update(GoodsDto dto);
}
